//
//  TrackModel.m
//  project
//
//  Created by 黄建华 on 2017/12/7.
//  Copyright © 2017年 黄建华. All rights reserved.
//

#import "TrackModel.h"

@implementation TrackModel

- (instancetype)init {
    self = [super init];
    if (self) {
        _user_id        = SN_USER.user_id;
        _date           = [[NSDate date] dateToString];
        _longitude      = 0.00;
        _latitude       = 0.00;
        _totalDistances = 0.00;
        _calorss        = 0.00;
        _sportTotalTime = 0;
        _averagePace    = 0.00;
        _maxSpeed       = 0.00;
        _averageSpeed   = 0.00;
        _imagePath      = @"";
        _startTime      = @"";
        _shareStrava = NO;
    }
    
    return self;
}

+ (TrackModel *)initWithDate:(NSDate *)date {
    TrackModel *model = [[TrackModel alloc] init];
    
    return model;
}
+ (TrackModel *)initWithDic:(NSDictionary *)dic{
    TrackModel *model = [[TrackModel alloc] init];
    model.imagePath = dic[@"track_image"];
    model.startTime = dic[@"date"];
    model.date = dic[@"date"];
    model.totalDistances = [dic[@"distance"] integerValue];
    model.sportTotalTime = [dic[@"duration"] integerValue];
    model.averagePace = [dic[@"average_pace"] integerValue];
    model.averageSpeed = [dic[@"average_speed"] floatValue];
    model.maxSpeed = [dic[@"fast_speed"] floatValue];
    model.calorss = [dic[@"cal"] integerValue];
    model.address = dic[@"location"];
    NSString *dataString = dic[@"data"];
    if ((NSNull *)dataString != [NSNull null]) {
         model.trackArray = (NSArray *)[dataString parseJSONString];
    }

    return model;
}
+ (NSMutableArray *)getUserInfoFromDBWithUserID:(NSString *)userID {
    NSString       *where = [NSString stringWithFormat:@"user_id = '%@'", userID];
    NSMutableArray *arr   = [NSMutableArray array];
    
    arr = [TrackModel searchWithWhere:where orderBy:nil offset:0 count:30];
    return arr;
}




// 表名
+ (NSString *)getTableName {
    return @"TrackModel";
}

// 复合主键
+ (NSArray *)getPrimaryKeyUnionArray {
    return @[@"user_id", @"date"];
}

// 表版本
+ (int)getTableVersion {
    return 1;
}

+ (void)initialize {
    [super initialize];
}


@end

